{layout name="../../admin/view/layout/main" /}
<div class="card">
    <div class="card-body">
        <form action="{:url('market/index/config')}?name={$app.name}" method="post" class="input-form needs-validation" novalidate>
            {foreach $items as $item}

                {if $item.type == 'input'}
                <div class="mb-3 row">
                    <label for="{$item.name}" class="col-sm-2 col-form-label">{$item.title} {if isset($item.required)}<font color="red">*</font>{/if}</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" value="{$item.value}" id="{$item.name}" name="{$item.name}" autocomplete="off" placeholder="{$item.placeholder}" {if isset($item.required)}required{/if}>
                        {if isset($item.help)}<div class="form-text">{$item.help|raw}</div>{/if}
                    </div>
                </div>
                {/if}

                {if $item.type == 'image'}
                    {:chooseOneImage($item['name'], $item['title'], $item['placeholder'], $item['required'] ?? false)}
                {/if}

                {if $item.type == 'images'}
                    {:chooseManyImage($item['name'], $item['title'], $item['placeholder'], $item['required'] ?? false)}
                {/if}

                {if $item.type == 'textarea'}
                <div class="mb-3 row">
                    <label for="{$item.name}" class="col-sm-2 col-form-label">{$item.title} {if isset($item.required)}<font color="red">*</font>{/if}</label>
                    <div class="col-sm-4">
                        <textarea class="form-control" id="{$item.name}" name="{$item.name}" autocomplete="off" placeholder="{$item.placeholder}" {if isset($item.required)}required{/if}>{$item.value}</textarea>
                    </div>
                </div>
                {/if}

                {if $item.type == 'select'}
                <div class="mb-3 row">
                    <label for="{$item.name}" class="col-sm-2 col-form-label">{$item.title} {if isset($item.required)}<font color="red">*</font>{/if}</label>
                    <div class="col-sm-10">
                        <select class="form-select" name="{$item.name}" id="{$item.name}" style="width: auto;" {if isset($item.required)}required{/if}>
                            <option value="">{$item.placeholder}</option>
                            {foreach $item.options as $opt}
                            {php}$selected = $item['value'] == $opt['value'] ? 'selected' : '';{/php}
                            <option value="{$opt.value}" {$selected}>{$opt.label}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                {/if}

                {if $item.type == 'select2'}
                <div class="mb-3 row">
                    <label for="{$item.name}" class="col-sm-2 col-form-label">{$item.title} {if isset($item.required)}<font color="red">*</font>{/if}</label>
                    <div class="col-sm-4">
                        <select class="form-select select2-{$item.name}" multiple name="{$item.name}[]" id="{$item.name}" {if isset($item.required)}required{/if}>
                            <option value="">{$item.placeholder}</option>
                            {foreach $item.options as $opt}
                            <option value="{$opt.value}">{$opt.label}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                {/if}

            {/foreach}
            <div class="mb-3 row">
                <label class="col-sm-2 col-form-label"></label>
                <div class="col-sm-10">
                    <button type="submit" class="btn btn-primary">确定</button>
                    <button type="button" class="btn btn-secondary" onclick="closeThisIframe();">关闭</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
     function closeThisIframe(){
        window.parent.layer.close(window.parent.layerIndex);
    }
    $(function () {
        validation_form('.input-form', function (){
            location.reload();
        });
        {foreach $items as $item}
            {if $item.type == 'select2'}
                $('.select2-{$item.name}').select2({
                    placeholder: '{$item.placeholder}',
                });
                {if $item.value}
                    $('.select2-{$item.name}').val('{$item.value}'.split(',')).trigger('change');
                {/if}
            {/if}
            {if $item.type == 'image'}
                {if $item.value}
                receiveDataFor{$item.name}('{$item.value}');
                {else /}
                deleteImageFor{$item.name}();
                {/if}
            {/if}
            {if $item.type == 'images'}
                {if $item.value}
                receiveDataFor{$item.name}('{$item.value}');
                {/if}
            {/if}
        {/foreach}
    })

</script>